package main

import "fmt"

type ListNode struct {
	Val  int
	Next *ListNode
}

func swapPairs(head *ListNode) *ListNode {
	cur := &ListNode{0, head}
	printList(cur)
	if head == nil || head.Next == nil {
		return head
	} else {
		first := cur
		h := head
		sceond := head.Next
		for {
			first.Next = sceond
			h.Next = sceond.Next
			sceond.Next = h
			printList(cur)
			if h.Next == nil || h.Next.Next == nil {
				break
			}
			first = first.Next.Next
			h = first.Next
			sceond = first.Next.Next
		}
		return cur.Next
	}
}

func printList(l1 *ListNode) {
	for temp1 := l1; temp1 != nil; temp1 = temp1.Next {
		fmt.Printf("%d->", temp1.Val)
	}
	fmt.Println("")
}
func main() {
	l1 := &ListNode{3, nil}
	l1temp := l1
	for i := 0; i < 2; i++ {
		temp := &ListNode{2 - i, nil}
		l1temp.Next = temp
		l1temp = l1temp.Next
	}
	printList(l1)
	swapPairs(l1)
}
